<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>RTOS - a cooperative multitasking library: RTOS::mutex Class Reference</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />

<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">RTOS - a cooperative multitasking library
   
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5.1 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li class="current"><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="annotated.html"><span>Class&#160;List</span></a></li>
      <li><a href="classes.html"><span>Class&#160;Index</span></a></li>
      <li><a href="hierarchy.html"><span>Class&#160;Hierarchy</span></a></li>
      <li><a href="functions.html"><span>Class&#160;Members</span></a></li>
    </ul>
  </div>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><a class="el" href="class_r_t_o_s.html">RTOS</a>      </li>
      <li class="navelem"><a class="el" href="class_r_t_o_s_1_1mutex.html">mutex</a>      </li>
    </ul>
  </div>
</div>
<div class="header">
  <div class="summary">
<a href="#pub-methods">Public Member Functions</a> &#124;
<a href="#friends">Friends</a>  </div>
  <div class="headertitle">
<div class="title">RTOS::mutex Class Reference</div>  </div>
</div>
<div class="contents">
<!-- doxytag: class="RTOS::mutex" -->
<p>mutual execlusion semaphore  
 <a href="class_r_t_o_s_1_1mutex.html#details">More...</a></p>

<p><code>#include &lt;<a class="el" href="p_r_t_o_s_8h_source.html">pRTOS.h</a>&gt;</code></p>

<p><a href="class_r_t_o_s_1_1mutex-members.html">List of all members.</a></p>
<table class="memberdecls">
<tr><td colspan="2"><h2><a name="pub-methods"></a>
Public Member Functions</h2></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_r_t_o_s_1_1mutex.html#a018aed6b83cf182b9990ac90a3254904">mutex</a> (const char *name=&quot;&quot;)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">constructor, specify the name  <a href="#a018aed6b83cf182b9990ac90a3254904"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_r_t_o_s_1_1mutex.html#a58255b4d832c8140f2b45efcc2065733">~mutex</a> (void)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">generates an error  <a href="#a58255b4d832c8140f2b45efcc2065733"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="aef6201cdf6b86c532629b5888d740303"></a><!-- doxytag: member="RTOS::mutex::print" ref="aef6201cdf6b86c532629b5888d740303" args="(std::ostream &amp;stream, bool header=true) const " -->
void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_r_t_o_s_1_1mutex.html#aef6201cdf6b86c532629b5888d740303">print</a> (std::ostream &amp;stream, bool header=true) const </td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">prints a mutex, for debugging only. <br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_r_t_o_s_1_1mutex.html#a52160d98a50d74a44fc4592a4625c6ed">wait</a> (void)</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="class_r_t_o_s_1_1mutex.html#a9a6cb88e182f977bce35e024449b24cd">signal</a> (void)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">release the mutex  <a href="#a9a6cb88e182f977bce35e024449b24cd"></a><br/></td></tr>
<tr><td colspan="2"><h2><a name="friends"></a>
Friends</h2></td></tr>
<tr><td class="memItemLeft" align="right" valign="top"><a class="anchor" id="aa5b30b5b619f01a5d94b779bf0e58610"></a><!-- doxytag: member="RTOS::mutex::RTOS" ref="aa5b30b5b619f01a5d94b779bf0e58610" args="" -->
class&#160;</td><td class="memItemRight" valign="bottom"><b>RTOS</b></td></tr>
</table>
<hr/><a name="details" id="details"></a><h2>Detailed Description</h2>
<div class="textblock"><p>mutual execlusion semaphore </p>
<p>A mutex (mutual exclusion semaphore) is a synchronization mechanism that is used to give a task exclusive access to some resource: the task can execute a sequence of statements, being sure that no other task is accessing the same resource.</p>
<p>A typical use is to protect a resource (for instance global data) that should be used by only one task at a time, so it can update it and leave it in a consistent state.</p>
<p>A mutex is not created for a particular task, and it is not a waitable.</p>
<p>Initially a mutex is free. The <a class="el" href="class_r_t_o_s_1_1mutex.html#a52160d98a50d74a44fc4592a4625c6ed">mutex::wait()</a> operation blocks the task until the mutex is free, and then claims the mutex for the executing task. The <a class="el" href="class_r_t_o_s_1_1mutex.html#a9a6cb88e182f977bce35e024449b24cd" title="release the mutex">mutex::signal()</a> operation frees the mutex again. It is an error to call <a class="el" href="class_r_t_o_s_1_1mutex.html#a9a6cb88e182f977bce35e024449b24cd" title="release the mutex">mutex::signal</a> on a mutex that is not currently owned by the executing task.</p>
<p>The example below shows two tasks that write messages to the LCD display. Each task writes to its own line. For the demonstration, after each LCD operation a sleep() is put to allow the other tasks to run. A mutex prevents the other task from accessing the LCD while the first one is still using it.</p>
<div class="fragment"><pre class="fragment"> TBW
</pre></div> </div><hr/><h2>Constructor &amp; Destructor Documentation</h2>
<a class="anchor" id="a018aed6b83cf182b9990ac90a3254904"></a><!-- doxytag: member="RTOS::mutex::mutex" ref="a018aed6b83cf182b9990ac90a3254904" args="(const char *name=&quot;&quot;)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">RTOS::mutex::mutex </td>
          <td>(</td>
          <td class="paramtype">const char *&#160;</td>
          <td class="paramname"><em>name</em> = <code>&quot;&quot;</code></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>constructor, specify the name </p>
<p>The name is used for debugging only. </p>

</div>
</div>
<a class="anchor" id="a58255b4d832c8140f2b45efcc2065733"></a><!-- doxytag: member="RTOS::mutex::~mutex" ref="a58255b4d832c8140f2b45efcc2065733" args="(void)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">RTOS::mutex::~mutex </td>
          <td>(</td>
          <td class="paramtype">void&#160;</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>generates an error </p>
<p>A mutex should never be destroyed </p>

</div>
</div>
<hr/><h2>Member Function Documentation</h2>
<a class="anchor" id="a9a6cb88e182f977bce35e024449b24cd"></a><!-- doxytag: member="RTOS::mutex::signal" ref="a9a6cb88e182f977bce35e024449b24cd" args="(void)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void RTOS::mutex::signal </td>
          <td>(</td>
          <td class="paramtype">void&#160;</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>release the mutex </p>
<p>If one or more tasks are waiting for the mutex the firs one is released, and it now owns the mutex. Otherwise, if the mutex is cleared it is now set.</p>
<p>It is an error for a task to call <a class="el" href="class_r_t_o_s_1_1mutex.html#a9a6cb88e182f977bce35e024449b24cd" title="release the mutex">signal()</a> on a mutex that it does not own (that it did not call <a class="el" href="class_r_t_o_s_1_1mutex.html#a52160d98a50d74a44fc4592a4625c6ed">wait()</a> on). After the signal the task no longer owns the mutex. </p>

</div>
</div>
<a class="anchor" id="a52160d98a50d74a44fc4592a4625c6ed"></a><!-- doxytag: member="RTOS::mutex::wait" ref="a52160d98a50d74a44fc4592a4625c6ed" args="(void)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void RTOS::mutex::wait </td>
          <td>(</td>
          <td class="paramtype">void&#160;</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">
<p>claim the mutex</p>
<p>If the mutex was set it it is now cleared, and the calling task owns the mutex.</p>
<p>Otherwise the current task waits (is halted) until the owning task calls <a class="el" href="class_r_t_o_s_1_1mutex.html#a9a6cb88e182f977bce35e024449b24cd" title="release the mutex">signal()</a> on the same mutex. The <a class="el" href="class_r_t_o_s_1_1mutex.html#a9a6cb88e182f977bce35e024449b24cd" title="release the mutex">signal()</a> calls will release the tasks in the order of their <a class="el" href="class_r_t_o_s_1_1mutex.html#a52160d98a50d74a44fc4592a4625c6ed">wait()</a> calls. </p>

</div>
</div>
<hr/>The documentation for this class was generated from the following file:<ul>
<li><a class="el" href="p_r_t_o_s_8h_source.html">pRTOS.h</a></li>
</ul>
</div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Friends</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>



<hr class="footer"/><address class="footer"><small>
Generated on Sat Apr 14 2012 15:59:31 for RTOS - a cooperative multitasking library by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.7.5.1
</small></address>

</body>
</html>
